#include "workthread.h"
#include "kernel.h"

WorkThread::WorkThread() {}

void WorkThread::run()
{
  using simu_kernel::in;
  using simu_kernel::IR;
  using simu_kernel::out;
  int ret = 1;
  while (ret)
  {
    IR = *simu_kernel::pc;
    ++simu_kernel::pc;
    if (OPCODE == binIN)
    {
      while (!in)
      {
        emit input();
        QThread::usleep(500);
      }
      in = false;
    }
    ret = (*simu_kernel::ops[OPCODE])();
    if (out)
    {
      emit output();
      out = false;
    }
    emit update();
    QThread::usleep(200);
  }
  simu_kernel::pc = simu_kernel::op;
}
